define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'my/collect/index',
                    // add_url: 'my/collect/add',
                    // edit_url: 'my/collect/edit',
                    del_url: 'my/collect/del',
                    detail_url: 'department/article/detail',
                    // multi_url: 'department/article/multi',
                    articlefile_url: 'my/article_file/index',
                    table: 'my',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id'), sortable: true},
                        {field: 'article.title', title: __('名称'), operate: 'LIKE', align: 'left',
                            formatter: function (value, row, index, field) {
                                return "<span style='display: block;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;' title='" + row.content + "'>" + value + "</span>";
                            },
                            cellStyle: function (value, row, index, field) {
                                return {
                                    css: {
                                        "white-space": "nowrap",
                                        "text-overflow": "ellipsis",
                                        "overflow": "hidden",
                                        "max-width": "300px"
                                    }
                                }
                            },},
                        {field: 'article.first_author', title: __('负责人'), operate: 'LIKE', formatter: Table.api.formatter.label},
                        {field: 'article.author', title: __('作者'), operate: 'LIKE', formatter: Table.api.formatter.label},
                        {field: 'article.introduction', title: __('简介'), operate: 'LIKE'},
                        {field: 'article.source', title: __('来源'), operate: 'LIKE'},
                        {field: 'article.direction', title: __('方向'), operate: 'LIKE'},
                        {field: 'article.territory', title: __('领域'), operate: 'LIKE'},
                        // {field: 'article.collect_num', title: __('收藏量'), operate: 'BETWEEN', formatter: Table.api.formatter.label},
                        {field: 'create_time', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons: [
                                {
                                    name: 'articlefile',
                                    text: __('附件'),
                                    title: __('附件'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    url: function(row){
                                        return $.fn.bootstrapTable.defaults.extend.articlefile_url + "?article_id=" + row.article.id;
                                    },
                                },
                                {
                                    name: 'detail',
                                    text: __('详情'),
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-warning btn-dialog',
                                    url: function(row){
                                        return $.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + row.article.id;
                                    },
                                },
                            ], formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});